#pragma once

#include <Ogre.h>
#include <MyGUI.h>

#include <OgreOggSound.h>

#include "NetworkClient.h"
#include "LuaLink.h"

class BaseApplication : public Ogre::FrameListener, OIS::MouseListener, OIS::KeyListener, NetworkListener {
public:

    MyGUI::Gui* mGui;
    Ogre::Root* mRoot;
    Ogre::RenderWindow* mWindow;
    OIS::Keyboard* mKeyboard;
    OIS::Mouse* mMouse;
    OIS::InputManager* mInputManager;
    Ogre::SceneManager* mSceneManager;
    Ogre::Camera* mCamera;
    Ogre::Viewport* mViewport;
	Ogre::RaySceneQuery* mRaySceneQuery;
	Ogre::ParticleSystemManager* mParticleSystemManager;
    NetworkClient* mNetwork;
	LuaLink* mLuaLink;
	OgreOggSound::OgreOggSoundManager *mSoundManager;
    bool running;
    
    virtual bool setupRoot();
    virtual bool setupResources();
    virtual bool loadResourceFile(const Ogre::String& fileName);
    virtual bool setupRenderSystem();
    virtual bool setupRenderWindow();
    virtual bool setupResourceGroups();
	virtual bool setupSoundManager();
    virtual bool setupScene();
	virtual bool setupSceneTools();
    virtual bool setupInputSystem();
    virtual bool setupGui();
    virtual bool setupFrameListener();
    virtual bool setupNetwork(const Ogre::String& host, int port);
	virtual bool setupLuaLink();
    virtual void startRenderLoop();
    virtual void cleanup();
    virtual void startup();
    virtual bool eachFrame(const Ogre::FrameEvent& evt);
    virtual bool createScene();
    
    BaseApplication();
    virtual ~BaseApplication();
    virtual bool frameStarted(const Ogre::FrameEvent& evt);
    virtual bool frameEnded(const Ogre::FrameEvent& evt);
    virtual bool mouseMoved(const OIS::MouseEvent& evt);
    virtual bool mousePressed(const OIS::MouseEvent& evt, OIS::MouseButtonID id);
    virtual bool mouseReleased(const OIS::MouseEvent& evt, OIS::MouseButtonID id);
    virtual bool keyPressed(const OIS::KeyEvent& evt);
    virtual bool keyReleased(const OIS::KeyEvent& evt);
    virtual void go();
    void trace(Ogre::String msg);
    void setupMouse();

    virtual unsigned long connectionMade(void* client);
    virtual unsigned long connectionFailed(void* client);
    virtual unsigned long dataReceived(void* client, const char* data, unsigned long length);
    virtual bool connectionLost(void* client);
    virtual void connectionClosed(void* client);
    virtual unsigned long connectionRestored(void* client);
};
